const express = require('express');
const router = express.Router();
const { 
  uploadDocument,
  processDocument,
  getUserDocuments,
  getDocumentById,
  getDocumentCards,
  updateDocument,
  deleteDocument,
  getDocumentChapters,
  generateDocumentSummary,
  reprocessDocument
} = require('../controllers/documentController');
const { protect } = require('../middlewares/auth');
const upload = require('../utils/fileUpload');

// 所有文档路由都需要身份验证
router.use(protect);

// 上传文档
router.post('/upload', upload.single('document'), uploadDocument);

// 处理文档
router.post('/:id/process', processDocument);

// 从失败的地方继续处理文档
router.post('/:id/reprocess', reprocessDocument);

// 获取用户的所有文档
router.get('/', getUserDocuments);

// 获取单个文档
router.get('/:id', getDocumentById);

// 获取文档的所有卡片
router.get('/:id/cards', getDocumentCards);

// 获取文档的章节列表
router.get('/:id/chapters', getDocumentChapters);

// 生成文档摘要
router.get('/:id/summary', generateDocumentSummary);

// 更新文档
router.put('/:id', updateDocument);

// 删除文档
router.delete('/:id', deleteDocument);

module.exports = router; 